import java.util.Arrays;
import java.util.Comparator;

public class project {
    public int twoCitySchedCost(int[][] costs) {
        Arrays.sort(costs, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return (o1[0]-o1[1])-(o2[0]-o2[1]);
            }
        });
        int len=costs.length/2;
        int ret=0;
        for(int i=0;i<len;i++){
            ret+=costs[i][0]+costs[i+len][1];
        }
        return ret;
    }





















    public String optimalDivision(int[] nums) {
        int len=nums.length;
        if(len==0){
            return null;
        }
        if(len==1){
            return nums[0]+"";
        }
        if(len==2){
            return nums[0]+"/"+nums[1];
        }
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<len;i++){
            if(i==0){
                sb.append(nums[i]).append("/").append("(");
            }else if(i==len-1){
                sb.append(nums[i]).append(")");
            }else{
                sb.append(nums[i]);
            }
        }
        return sb.toString();
    }
}
